$(document).ready(function () {
    list();

    window.parent.setLiAbled();
});

function list() {
    $.ajax({
        url: APP_ADDRESS + "/app/version/list",
        type: "GET",
        contentType: 'application/json',
        cache: false,
        success: function (data) {
            if (data.resultCode == '200') {
                $('#tableList tbody').empty();
                var tr = '';
                if (data.result != null && data.result.length > 0) {
                    for (var i = 0; i < data.result.length; i++) {

                        var singleObj = data.result[i];
                        localStorage.setItem(singleObj.id + "_ProductVer_Key", JSON.stringify(singleObj));

                        tr += '<tr><td>'
                            + '<input type="hidden" id ="id" name="id" value="' + singleObj.id + '"/>'
                            + '<input type="hidden" id ="channel" name="channel" value="' + singleObj.channel + '"/>'
                            + '<input type="hidden" id ="phoneType" name="phoneType" value="' + singleObj.phoneType + '"/>'
                            + (i + 1)
                            + '</td><td>'
                            + singleObj.channelText  //客户端
                            + '</td><td>'
                            + singleObj.version   //版本号
                            + '</td><td>'
                            + singleObj.phoneType //操作系统
                            + '</td><td>'
                            + singleObj.isFocusUpdateText //强制更新
                            + '</td><td>'
                            + singleObj.name //标题
                            + '</td><td>'
                            + singleObj.description //描述
                            + '</td><td>'
                            + singleObj.LastUpdated //时间
                            + '</td><td>'
                            + singleObj.operator //操作人
                            + '</td><td>'
                            + '<a type="button" name="sysProductVer_96" id="btnUpdate" style="margin-left: 5px;display:none;" class="btn btn-success btn-xs updateData">'
                            + '<i class="fa fa-edit"></i> 编辑</a>'
                            + '<a type="button" name="sysProductVer_99" class="btn btn-primary btn-xs lookData" style="margin-left: 5px;display:none;">'
                            + '<i class="fa fa-reorder"></i> 历史版本 </a>'
                            + '</td></tr>';
                    }
                }
                else {
                    tr = '<tr><td colspan="6" style="text-align: center;color: red;">暂无数据</td></tr>';
                }

                $('#tableList tbody').html(tr);
                jsUtils.controlFunctionBtn();
                bindButtons();
            }
        },
        error: function (data) {
            console.log("查询失败: " + data.result);
            console.log(data);
        }
    });
}

function bindButtons() {
    $('.updateData').unbind();
    $('.updateData').on('click', function () {
        var thisObj = $(this);

        var id = thisObj.parent().parent().find('input[name="id"]').eq(0).val();
        art.dialog.data('id', id);
        console.log(id);

        var path = APP_ADDRESS + 'mgr/sysMgr/appVersion/update.jsp';
        art.dialog.open(path, {
            title: '修改系统版本',
            width: 600,
            height: 450,
            ok: function () {

                var callBack = list;
                this.iframe.contentWindow.submitForm(callBack);

                return false;
            },
            cancel: true
        });
    });

    $('.lookData').unbind();
    $('.lookData').on('click', function () {
        var thisObj = $(this);

        var channel = thisObj.parent().parent().find('input[name="channel"]').eq(0).val();
        var phoneType = thisObj.parent().parent().find('input[name="phoneType"]').eq(0).val();
        art.dialog.data('channel', channel);
        art.dialog.data('phoneType', phoneType);

        var path = APP_ADDRESS + 'mgr/sysMgr/appVersion/history.jsp';
        art.dialog.open(path, {
            title: '查看系统版本',
            width: 800,
            height: 600,
            cancel: true
        });
    });
}
